package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.layout.DefaultLayoutHelper;

import java.util.ArrayList;
import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.ApphomeModuleStandbyViewBinding;
import sz.szsmk.citizencard.model.network.bean.response.QueryNearStandbyRes;
import sz.szsmk.citizencard.model.network.clarkbean.response.AdInfo;

/**
 * Copyright (c)2020
 * author: Clark
 * created on:2020年10月7日 16点06分
 * description: App出行规划共交模块
 */
public class TripPlanBusAdapter extends DelegateAdapter.Adapter<TripPlanBusAdapter.TripPlanBusHolder> {
    private Context mContext;
    private LayoutHelper mGridLayoutHelper;
    private QueryNearStandbyRes viewData;
    private TripPlanBusListAdapter tripPlanBusListAdapter;
    private BaseInterface baseInterface;
    private int subwayNum;

    public interface BaseInterface {
        public void onClick(View view, QueryNearStandbyRes.BusSiteListBean bean);
    }

    public void setBaseInterface(BaseInterface baseInterface) {
        this.baseInterface = baseInterface;
    }

    public TripPlanBusAdapter(Context context, DefaultLayoutHelper headHelper,int subwayNum) {
        mContext = context;
        mGridLayoutHelper = headHelper;
        this.subwayNum=subwayNum;

    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mGridLayoutHelper;
    }

    @Override
    public TripPlanBusHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//        View view = LayoutInflater.from(mContext).inflate(R.layout.apphome_head_view_new, parent, false);
        return  TripPlanBusHolder.creat(parent);
    }

    @Override
    public int getItemViewType(int position) {
        return R.layout.apphome_module_standby_view;
    }

    @Override
    public void onBindViewHolder(TripPlanBusHolder holder, int position) {
//        holder.blurringView.setBlurredView();

        loadItemData(position, holder.binding);

    }
    private void loadItemData(int position, ApphomeModuleStandbyViewBinding binding) {
        if (viewData != null) {
            binding.stationTitle.setVisibility(View.VISIBLE);
            binding.stationTitle.setText("附近公交站点");
            LinearLayoutManager manager=new LinearLayoutManager(mContext);
            tripPlanBusListAdapter = new TripPlanBusListAdapter(mContext);
            tripPlanBusListAdapter.setBaseInterface(new TripPlanBusListAdapter.BaseInterface() {
                @Override
                public void onClick(View view, QueryNearStandbyRes.BusSiteListBean bean) {
                    //单元数据的点击事件 需要增加
                    if(baseInterface!=null){
                        baseInterface.onClick(view,bean);
                    }
                }
            });

            binding.collecNearStationRv.setLayoutManager(manager);
            binding.collecNearStationRv.setAdapter(tripPlanBusListAdapter);
            tripPlanBusListAdapter.setViewData(viewData,subwayNum);
            tripPlanBusListAdapter.notifyDataSetChanged();
        }else {
            binding.stationTitle.setVisibility(View.GONE);
        }

    }
    @Override
    public int getItemCount() {
        return 1;
    }


    public void setViewData(QueryNearStandbyRes viewData) {
        this.viewData = viewData;
        this.notifyDataSetChanged();
    }


    public static class TripPlanBusHolder extends RecyclerView.ViewHolder {
        private ApphomeModuleStandbyViewBinding binding;

        public static TripPlanBusHolder creat(ViewGroup parent) {
            ApphomeModuleStandbyViewBinding binding =
                    ApphomeModuleStandbyViewBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);

            return new TripPlanBusHolder(binding);
        }

        public TripPlanBusHolder(ApphomeModuleStandbyViewBinding binding) {
            super(binding.getRoot());


            this.binding = binding;
        }

    }

}
